package com.wyy.controller;

import com.wyy.pojo.AppreciatesOrder;
import com.wyy.pojo.Users;
import com.wyy.pojo.model.UserModel;
import com.wyy.pojo.model.UserToken;
import com.wyy.response.CommonReturnType;
import com.wyy.web.UserFeignAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: gytcb
 * @author: 吴磊
 * @create: 2021-06-02 13:24
 */
@RestController
public class UserController {
    @Autowired
    private UserFeignAction userFeignAction;

    /**
     * 根据用户名称模糊查询用户
     *
     * @param userToken
     * @return
     */
    @RequestMapping(value = "/getUserByNameLike", method = RequestMethod.POST)
    public CommonReturnType getUserByNameLike(@RequestBody UserToken userToken) {
        return userFeignAction.getUserByNameLike(userToken);
    }


    /**
     * 检查订单支付状态
     *
     * @param appreciatesOrder
     * @return
     */
    @RequestMapping(value = "/checkOrderStatus", method = RequestMethod.POST)
    public CommonReturnType checkOrderStatus(@RequestBody AppreciatesOrder appreciatesOrder) {
        return userFeignAction.checkOrderStatus(appreciatesOrder);
    }


    /**
     * 获取支付二维码
     *
     * @param appreciatesOrder
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getQrCode", method = {RequestMethod.POST})
    public CommonReturnType FacetoFacePay(@RequestBody AppreciatesOrder appreciatesOrder) throws Exception {
        return userFeignAction.FacetoFacePay(appreciatesOrder);
    }


    /**
     * 异步回调接口
     */
    @RequestMapping(value = "/notifyUrl", method = RequestMethod.POST)
    public String notifyInterface(HttpServletRequest request) throws Exception {
        Map<String, String> mapParams = new HashMap();
        Enumeration<String> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String key = parameterNames.nextElement();
            String value = request.getParameter(key);
            mapParams.put(key, value);
        }
        return userFeignAction.notifyInterface(mapParams);
    }


    /**
     * 检查用户是否登录
     *
     * @return
     */
    @RequestMapping(value = "/checkUserIsLogin", method = {RequestMethod.POST})
    public CommonReturnType checkUserIsLogin() {
        return userFeignAction.checkUserIsLogin();
    }

    @RequestMapping(value = "/getAllUser", method = {RequestMethod.GET})
    public CommonReturnType getAlluser() {
        return userFeignAction.getAllUser();
    }

    /**
     * 用户登录接口
     *
     * @param userModel
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public CommonReturnType login(@RequestBody UserModel userModel) {
        return userFeignAction.login(userModel);
    }


    /**
     * 退出登录
     *
     * @return
     */
    @RequestMapping(value = "/loginOut", method = RequestMethod.POST)
    CommonReturnType loginOut() {
        return userFeignAction.loginOut();
    }

    /**
     * 验证用户名是否存在
     *
     * @param userNickName
     * @return
     */
    @RequestMapping(value = "/checkUserNickName", method = RequestMethod.POST)
    public CommonReturnType getUserByUserNickname(@RequestBody String userNickName) {
        return userFeignAction.getUserByUserNickname(userNickName);
    }

    /**
     * 验证邮箱是否存在
     *
     * @param userEmail
     * @return
     */
    @RequestMapping(value = "/checkUserEmail", method = RequestMethod.POST)
    public CommonReturnType getUserByUserEmail(@RequestBody String userEmail) {
        return userFeignAction.getUserByUserEmail(userEmail);
    }

    /**
     * 用户注册接口
     *
     * @param users
     * @return
     */
    @RequestMapping(value = "/registerUser", method = RequestMethod.POST)
    public CommonReturnType registerUser(@RequestBody Users users) {
        return userFeignAction.registerUser(users);
    }

    /**
     * 更新用户头像路径
     *
     * @param file
     * @return
     */
    @RequestMapping(value = "/updateUserFilePath", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    CommonReturnType tokenUpdateUserFilePath(MultipartFile file) {
        return userFeignAction.tokenUpdateUserFilePath(file);
    }

    /**
     * 更新用户信息
     *
     * @param users
     * @return
     */
    @RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST)
    CommonReturnType tokenUpdateUserInfo(@RequestBody Users users) {
        return userFeignAction.tokenUpdateUserInfo(users);
    }

    /**
     * 验证用户修改密码的时候密码是否正确
     *
     * @param userPassword
     * @return
     */
    @RequestMapping(value = "/checkUserPasswordIsOk", method = RequestMethod.POST)
    public CommonReturnType tokenCheckUserPasswordIsOk(@RequestBody String userPassword) {
        return userFeignAction.tokenCheckUserPasswordIsOk(userPassword);
    }

    /**
     * 获取用户的详细信息（不包括密码）
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.POST)
    public CommonReturnType getUserInfo(@RequestBody String userId) {
        return userFeignAction.getUserInfo(userId);
    }

}